package com.example.demo.common;

import com.amazonaws.services.dynamodbv2.xspec.S;
import com.example.demo.common.entity.TestDTO;

import java.util.*;

public class Test07 {

    private static Map<Integer, List<Integer>> map;

    static {
        map = new HashMap<>();
        map.put(1, Arrays.asList(1, 2, 3));
        map.put(2, Arrays.asList(4, 5, 6));
        map.put(3, Arrays.asList(7, 8, 9));
    }

    public static void main(String[] args) {
        int i = 0;
        int n = i++;
        System.out.println(n);

        System.out.println(i++);
        System.out.println(++i);

        System.out.println();
        System.out.println();
        System.out.println();

        List<Object> xList = new ArrayList<>();
        List<Object> yList = new ArrayList<>();

        TestDTO dto = TestDTO.builder()
                .name("ceshi").xList(xList).yList(yList).map(map)
                .build();

        List<Integer> idList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
        introductionAddDrawCanvas(dto, idList);

        List<Integer> idList1 = Arrays.asList(12, 12, 13);
        introductionAddDrawCanvas(dto, idList1);

        List<Integer> idList2 = Arrays.asList(22, 22, 23);
        map.put(1, Arrays.asList(11, 12, 13));
        introductionAddDrawCanvas(dto, idList2);
    }

    private static void introductionAddDrawCanvas(TestDTO dto, List<Integer> idList) {
        List<Object> xList = dto.getXList();
        List<Object> yList = dto.getYList();

        List<Object> result = new ArrayList<>();

        idList.forEach(x -> {
            result.add(x);
        });
        xList.addAll(result);

        Collections.shuffle(result);

        List<Integer> notInImgTemplateIdList = Arrays.asList(1, 2);
        List<Integer> usedImgTemplateIdList = Arrays.asList(3, 4);

        Optional<Object> canvasDTO = result.stream()
                // 过滤已被使用的和不能被包含的产品模板
                .filter(x -> !notInImgTemplateIdList.contains(x) && !usedImgTemplateIdList.contains(x)).findFirst();
        canvasDTO.ifPresent(yList::add);
    }
}
